home *** CD-ROM | disk | FTP | other *** search
/ Champak 106 / Vol 106.iso / games / insuranc.swf / scripts / __Packages / PlayerCar.as < prev    next >
Encoding:
Text File  |  2010-04-12  |  9.8 KB  |  389 lines

  1. class PlayerCar
  2. {
  3.    var pos;
  4.    var vel;
  5.    var acc;
  6.    var maxVel;
  7.    var sEnemy;
  8.    var energy;
  9.    var blinkInd;
  10.    var exitDelay;
  11.    var deadTime;
  12.    var bDestroyed;
  13.    var bEnter;
  14.    var bExit;
  15.    var bShield;
  16.    var bAllowShooting;
  17.    var mcCanvas;
  18.    var mcCar;
  19.    var width;
  20.    var height;
  21.    var bSkid;
  22.    var bPuddle;
  23.    var skidRot;
  24.    var weaponFrame;
  25.    var mcWeapon;
  26.    var mcWeaponArea;
  27.    var skidDir;
  28.    function PlayerCar(newPos, mcCanvasNew, sEnemyNew)
  29.    {
  30.       this.pos = newPos.clone();
  31.       this.vel = new flash.geom.Point(0,0);
  32.       this.acc = new flash.geom.Point(0,0);
  33.       this.maxVel = 20;
  34.       this.sEnemy = sEnemyNew;
  35.       this.energy = 100;
  36.       this.blinkInd = 0;
  37.       this.exitDelay = 10;
  38.       this.deadTime = 0;
  39.       this.bDestroyed = false;
  40.       this.bEnter = true;
  41.       this.bExit = false;
  42.       this.bShield = false;
  43.       this.bAllowShooting = true;
  44.       this.mcCanvas = mcCanvasNew;
  45.       this.mcCar = this.mcCanvas.attachMovie("player car","mcCar",999);
  46.       this.setWeapon();
  47.       this.width = 48;
  48.       this.height = 48;
  49.       this.bSkid = false;
  50.       this.bPuddle = false;
  51.       this.draw();
  52.    }
  53.    function step(Void)
  54.    {
  55.       if(this.bDestroyed)
  56.       {
  57.          if(this.deadTime-- == 0)
  58.          {
  59.             this.bDestroyed = false;
  60.             this.die();
  61.          }
  62.          return undefined;
  63.       }
  64.       if(this.bEnter)
  65.       {
  66.          if(this.pos.y < 50)
  67.          {
  68.             this.pos.y += 5;
  69.          }
  70.          else
  71.          {
  72.             this.pos.y = 50;
  73.             this.showWeapon();
  74.             this.bEnter = false;
  75.          }
  76.          return undefined;
  77.       }
  78.       if(this.bExit)
  79.       {
  80.          this.vel.x = 0;
  81.          if(this.exitDelay-- <= 0)
  82.          {
  83.             if(this.pos.y < 500)
  84.             {
  85.                this.pos.y += 25;
  86.             }
  87.             else
  88.             {
  89.                this.pos.y = 500;
  90.                Game.getInstance().onPlayerOut();
  91.             }
  92.          }
  93.          return undefined;
  94.       }
  95.       if(this.bSkid)
  96.       {
  97.          if(this.skidRot < 360)
  98.          {
  99.             this.skidRot += 18;
  100.          }
  101.          else
  102.          {
  103.             this.bSkid = false;
  104.             this.skidRot = 360;
  105.          }
  106.       }
  107.       else
  108.       {
  109.          this.keyControl();
  110.       }
  111.       this.vel.x += this.acc.x;
  112.       this.vel.y += this.acc.y;
  113.       if(this.acc.x == 0)
  114.       {
  115.          this.vel.x *= 0.7;
  116.       }
  117.       if(this.vel.y < 0)
  118.       {
  119.          this.vel.y = 0;
  120.       }
  121.       else if(this.vel.y > this.maxVel)
  122.       {
  123.          this.vel.y = this.maxVel;
  124.       }
  125.       if(this.vel.x < (- this.maxVel) / 2)
  126.       {
  127.          this.vel.x = (- this.maxVel) / 2;
  128.       }
  129.       else if(this.vel.x > this.maxVel / 2)
  130.       {
  131.          this.vel.x = this.maxVel / 2;
  132.       }
  133.       this.pos.x += this.vel.x * this.vel.y / this.maxVel;
  134.       this.pos.y = 50 + 70 * this.vel.y / this.maxVel;
  135.       if(this.pos.x < this.width / 2)
  136.       {
  137.          this.pos.x = this.width / 2;
  138.       }
  139.       else if(this.pos.x > Game.screenW - this.width / 2)
  140.       {
  141.          this.pos.x = Game.screenW - this.width / 2;
  142.       }
  143.       if(this.blinkInd > 0)
  144.       {
  145.          this.blinkInd = this.blinkInd - 1;
  146.          this.blink();
  147.       }
  148.       if(!this.bAllowShooting)
  149.       {
  150.          if(this.weaponFrame == this.mcWeapon.mcAnim._currentframe)
  151.          {
  152.             this.bAllowShooting = true;
  153.             this.mcWeaponArea = undefined;
  154.          }
  155.          this.weaponFrame = this.mcWeapon.mcAnim._currentframe;
  156.          if(this.mcWeaponArea == undefined)
  157.          {
  158.             this.mcWeaponArea = this.mcWeapon.mcAnim.mcHitArea;
  159.          }
  160.       }
  161.    }
  162.    function draw(Void)
  163.    {
  164.       this.mcCar._x = this.pos.x;
  165.       this.mcCar._y = Game.screenH - this.pos.y;
  166.       if(!this.bSkid)
  167.       {
  168.          this.mcCar._rotation = this.vel.x * Math.ceil(this.vel.y / this.maxVel);
  169.       }
  170.       else
  171.       {
  172.          this.mcCar._rotation = this.skidRot * this.skidDir;
  173.       }
  174.    }
  175.    function keyControl(Void)
  176.    {
  177.       var _loc2_ = 38;
  178.       var _loc6_ = 40;
  179.       var _loc3_ = 37;
  180.       var _loc4_ = 39;
  181.       var _loc5_ = 32;
  182.       var _loc7_ = 88;
  183.       var _loc8_ = 90;
  184.       this.acc.y = 0;
  185.       if(Key.isDown(_loc2_))
  186.       {
  187.          this.acc.y = 0.5;
  188.       }
  189.       else if(Key.isDown(_loc6_))
  190.       {
  191.          this.acc.y = -0.5;
  192.       }
  193.       this.acc.x = 0;
  194.       if(Key.isDown(_loc3_))
  195.       {
  196.          this.acc.x = -2;
  197.       }
  198.       else if(Key.isDown(_loc4_))
  199.       {
  200.          this.acc.x = 2;
  201.       }
  202.       if(Key.isDown(_loc5_) && this.bAllowShooting)
  203.       {
  204.          this.bAllowShooting = false;
  205.          this.shoot();
  206.       }
  207.    }
  208.    function getRect(Void)
  209.    {
  210.       var _loc2_ = this.mcCar.getRect(this.mcCanvas);
  211.       return new flash.geom.Rectangle(_loc2_.xMin,_loc2_.yMin,_loc2_.xMax - _loc2_.xMin,_loc2_.yMax - _loc2_.yMin);
  212.    }
  213.    function reactionOnShoulder(bmpShoulder)
  214.    {
  215.       var _loc6_ = Math.sqrt(this.width * this.width + this.height * this.height) / 2;
  216.       var _loc4_ = new flash.geom.Point(this.mcCar._x - this.width / 2,this.mcCar._y - this.height / 2);
  217.       var _loc2_ = new flash.geom.Point(this.mcCar._x + this.width / 2,this.mcCar._y - this.height / 2);
  218.       if(bmpShoulder.hitTest(new flash.geom.Point(0,0),250,_loc4_))
  219.       {
  220.          this.vel.x = this.vel.y / 2;
  221.          if(this.vel.x < 2)
  222.          {
  223.             this.vel.x = 2;
  224.          }
  225.          this.pos.x += this.vel.x;
  226.          var _loc3_ = 10 * Math.ceil(this.vel.y / this.maxVel * 2);
  227.          this.getDamage(_loc3_);
  228.          Sounds.playSound("carCrash");
  229.       }
  230.       else if(bmpShoulder.hitTest(new flash.geom.Point(0,0),250,_loc2_))
  231.       {
  232.          this.vel.x = (- this.vel.y) / 2;
  233.          if(this.vel.x > -2)
  234.          {
  235.             this.vel.x = -2;
  236.          }
  237.          this.pos.x += this.vel.x;
  238.          _loc3_ = 10 * Math.ceil(this.vel.y / this.maxVel * (!Application.bEasy ? 3 : 2));
  239.          this.getDamage(_loc3_);
  240.          Sounds.playSound("carCrash");
  241.       }
  242.    }
  243.    function getDamage(damage)
  244.    {
  245.       if(this.bEnter || this.bExit || this.bShield)
  246.       {
  247.          return undefined;
  248.       }
  249.       if(this.blinkInd == 0)
  250.       {
  251.          this.energy -= damage;
  252.       }
  253.       if(this.energy <= 0)
  254.       {
  255.          this.energy = 0;
  256.          this.deadTime = 10;
  257.          this.bDestroyed = true;
  258.          this.mcCar.gotoAndStop("dead");
  259.       }
  260.       else
  261.       {
  262.          this.blinkInd = 30;
  263.       }
  264.       Game.getInstance().setEnergyMeter(this.energy);
  265.    }
  266.    function die(Void)
  267.    {
  268.       this.vel.x = 0;
  269.       this.vel.y = 0;
  270.       Game.getInstance().loseLife();
  271.    }
  272.    function blink(Void)
  273.    {
  274.       var _loc3_ = undefined;
  275.       if(this.blinkInd % 2 == 1)
  276.       {
  277.          var _loc2_ = Math.round(255 * this.blinkInd / 30);
  278.          _loc3_ = new flash.geom.ColorTransform(1,1,1,1,_loc2_,_loc2_,_loc2_,0);
  279.       }
  280.       else
  281.       {
  282.          _loc3_ = new flash.geom.ColorTransform(1,1,1,1,0,0,0,0);
  283.       }
  284.       var _loc4_ = new flash.geom.Transform(this.mcCar);
  285.       _loc4_.colorTransform = _loc3_;
  286.    }
  287.    function showWeapon(Void)
  288.    {
  289.       this.mcWeapon.mcAnim.gotoAndPlay("show");
  290.    }
  291.    function hideWeapon(Void)
  292.    {
  293.       this.mcWeapon.mcAnim.gotoAndPlay("hide");
  294.    }
  295.    function shoot(Void)
  296.    {
  297.       this.mcWeapon.mcAnim.gotoAndPlay("shot");
  298.       this.weaponFrame = this.mcWeapon.mcAnim._currentframe + 1;
  299.       if(this.sEnemy == "sainsbury" || this.sEnemy == "moreThan" || this.sEnemy == "admiral")
  300.       {
  301.          this.mcWeaponArea = Game.getInstance().createShot(this.sEnemy);
  302.       }
  303.    }
  304.    function checkObstacle(mcObstacle)
  305.    {
  306.       var _loc2_ = Game.getInstance().sEnemy;
  307.       if(mcObstacle.hitTest(this.mcCar._x,this.mcCar._y))
  308.       {
  309.          this.getDamage(30);
  310.       }
  311.    }
  312.    function checkPuddle(refPuddle)
  313.    {
  314.       if(this.mcCar.mcWheels.hitTest(refPuddle.mcPuddle))
  315.       {
  316.          if(refPuddle.type == 0 && !this.bSkid)
  317.          {
  318.             if(this.vel.y > 2 && !this.bPuddle)
  319.             {
  320.                this.vel.y *= 0.6;
  321.                this.bSkid = true;
  322.                this.bPuddle = true;
  323.                this.skidRot = 0;
  324.                if(this.vel.x > 0)
  325.                {
  326.                   this.skidDir = 1;
  327.                }
  328.                else
  329.                {
  330.                   this.skidDir = -1;
  331.                }
  332.                Sounds.playSound("tyrescreech");
  333.             }
  334.          }
  335.          else if(refPuddle.type == 1)
  336.          {
  337.             if(this.vel.y > 2)
  338.             {
  339.                this.vel.y *= 0.9;
  340.             }
  341.             if(!this.bPuddle)
  342.             {
  343.                this.bPuddle = true;
  344.                Sounds.playSound("splash");
  345.             }
  346.          }
  347.       }
  348.       else
  349.       {
  350.          this.bPuddle = false;
  351.       }
  352.    }
  353.    function remove(Void)
  354.    {
  355.       this.mcCar.removeMovieClip();
  356.       false;
  357.    }
  358.    function setWeapon(Void)
  359.    {
  360.       this.mcWeapon = this.mcCar.mcWeapon;
  361.       this.mcWeapon.gotoAndStop(this.sEnemy);
  362.    }
  363.    function newLife(Void)
  364.    {
  365.       this.mcCar.gotoAndStop("alive");
  366.       this.energy = 100;
  367.       this.bEnter = true;
  368.       this.pos.y = -50;
  369.       this.setWeapon();
  370.       this.bPuddle = false;
  371.    }
  372.    function setShieldOn(Void)
  373.    {
  374.       this.bShield = true;
  375.       var _loc5_ = 16777215;
  376.       var _loc11_ = 0.8;
  377.       var _loc8_ = 8;
  378.       var _loc7_ = 8;
  379.       var _loc9_ = 50;
  380.       var _loc3_ = 1;
  381.       var _loc6_ = false;
  382.       var _loc10_ = false;
  383.       var _loc4_ = new flash.filters.GlowFilter(_loc5_,_loc11_,_loc8_,_loc7_,_loc9_,_loc3_,_loc6_,_loc10_);
  384.       var _loc2_ = new Array();
  385.       _loc2_.push(_loc4_);
  386.       this.mcCar.filters = _loc2_;
  387.    }
  388. }
  389.